<%@ page language="java"  pageEncoding="utf-8"%>
<%@ page import="java.util.Vector,com.ejoysoft.common.Constants,com.ejoysoft.common.exception.NoRightException" %>
<%@page import="com.ejoysoft.wlanyz.business.Proportion"%>
<%@ include file="../include/jsp/head.jsp"%>
<%
if(!globa.userSession.hasRight("20020"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
%>
<%
    //初始化
    Proportion  ap0=null;
    Proportion obj=new Proportion(globa);
    //查询条件
    String  strCity = ParamUtil.getString(request,"strCity","");
    String  strTown = ParamUtil.getString(request,"strTown","");	
    String  strStartTime = ParamUtil.getString(request,"strStartTime","");
    String  strEndTime = ParamUtil.getString(request,"strEndTime","");
    String exportFlag = ParamUtil.getString(request,"exportFlag","");
	String exportContent = ParamUtil.getString(request,"exportContent","");
	String  strOneAc = ParamUtil.getString(request,"strOneAc","");
	String  strTwoAc = ParamUtil.getString(request,"strTwoAc","");
	String  strAp = ParamUtil.getString(request,"strAp","");
	
		//当前页
		System.out.println("111111111111"+strTwoAc);
    int intCurPage = ParamUtil.getInt(request,"strCurPage");
	String tWhere=" WHERE 1=1";
 String WhereAp=" WHERE 1=1 and b.strcity = '"+strCity+"' and b.strtown= '"+strTown+"' and b.strclassonehp = '"+strOneAc+"' and strhotpotname = '"+strTwoAc+"' ";
    
	//记录总数
	int intAllCount = 0;	
	if(exportFlag.equals("results_city")){//地市
	 if(!strCity.equals("")){
     tWhere += " and strCity LIKE '%"+ strCity +"%'";
    }
	 intAllCount = obj.getCount(tWhere);
	}
	if(exportFlag.equals("results_town")){//区县
	tWhere+= " and strcity = '"+strCity+"' ";
	if(!strTown.equals("")){
     tWhere += " and strTown LIKE '%"+ strTown +"%'";     
    }
	 intAllCount = obj.getCount1(tWhere);
	}
	else if(exportFlag.equals("results_oneac")){//一级热点
	tWhere+= " and strcity = '"+strCity+"' and strtown = '"+strTown+"' ";
	if(!strOneAc.equals("")){
     tWhere += " and strclassonehp LIKE '%"+ strOneAc +"%'";     
    }
	 intAllCount = obj.getCount2(tWhere);
	}
	else if(exportFlag.equals("results_twoac")){//二级热点
	tWhere+= " and strcity = '"+strCity+"' and strtown = '"+strTown+"' and strclassonehp = '"+strOneAc+"' ";
	if(!strTwoAc.equals("")){
     tWhere += " and strhotpotname LIKE '%"+ strTwoAc +"%'";     
    }
	 intAllCount = obj.getCount3(tWhere);
	}
	else if(exportFlag.equals("results_ap")){//AP
	 if(!strAp.equals("")){
     WhereAp += " and strAp LIKE '%"+ strAp +"%'";     
    }
	 intAllCount = obj.getCount4(WhereAp);
	}
	
	//每页记录数
    String strPageSize = ParamUtil.getString(request,"strPageSize","10");
    int intPageSize;
    if(strPageSize.equals("所有"))intPageSize = intAllCount;
      else  intPageSize = Integer.parseInt(strPageSize);
	//共有页数
 	int intPageCount=(intAllCount-1)/intPageSize+1;
	// 循环显示一页内的记录 开始序号
	int intStartNum=(intCurPage-1)*intPageSize+1;
	//结束序号
	int intEndNum=intCurPage*intPageSize;   
	//获取到当前页面的记录集
	
	StringBuffer sb = new StringBuffer("<html><body><table border='1'>");
	String strFileName = "";
	System.out.println("==========================;;;======"+intAllCount);
	System.out.println("================================"+exportFlag);
	if(exportFlag.equals("results_city"))
	{
	    Vector<Proportion> vctObj=obj.list(tWhere,intStartNum,intPageSize);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list(tWhere,0,0);
		}
   	  double proportion1  = 0;
        int num = 0;
	    sb.append("<tr><td>城市</td><td>区县数量</td><td>一级热点数量</td><td>二级热点数量</td><td>AP数量</td><td>已测AP数</td><td>已测AP百分比</td></tr>");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		    num = vctObj.get(i).getTestAp(vctObj.get(i).getStrCity(),strStartTime,strEndTime);
            	if(vctObj.get(i).getAp(vctObj.get(i).getStrCity())!=0){
            	 proportion1 =  num*100/vctObj.get(i).getAp(vctObj.get(i).getStrCity());
            	 }else{
            	 proportion1 = 0;
            	 }
		       sb.append("<tr><td>"+vctObj.get(i).getStrCity());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getTownNum());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getOneAcNum());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getTwoAcNum()) ;
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getAp(vctObj.get(i).getStrCity())) ;
		       sb.append("</td><td>");
		       sb.append(num );
		       sb.append("</td><td>");
		       sb.append(proportion1 );
		       sb.append("%</td></tr>");
		    }
	    }
	     strFileName = strCity+"测试完成比例表.xls";//自定义xls文件的文件
	} 
	if(exportFlag.equals("results_town"))
	{
	    Vector<Proportion> vctObj=obj.list2(tWhere,intStartNum,intPageSize);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list2(tWhere,0,0);
		}
   	  
	    sb.append("<tr><td>城市</td><td>区县</td><td>一级热点数量</td><td>二级热点数量</td><td>AP数量</td><td>已测AP数</td><td>已测AP百分比</td></tr>");
	    if (vctObj.size() != 0)
	    {
	    double proportion1  = 0;
        int num = 0;
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		    num = vctObj.get(i).getTestAp(strCity, vctObj.get(i).getStrTown(),strStartTime,strEndTime);
            	if(vctObj.get(i).getAp(strCity, vctObj.get(i).getStrTown())!=0){
            	 proportion1 =  num*100/vctObj.get(i).getAp(strCity,vctObj.get(i).getStrTown());
            	 }else{
            	 proportion1 = 0;
            	 }
		       sb.append("<tr><td>"+strCity);
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getStrTown());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getOneAcNum());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getTwoAcNum()) ;
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getAp(strCity, vctObj.get(i).getStrTown())) ;
		       sb.append("</td><td>");
		       sb.append(num );
		       sb.append("</td><td>");
		       sb.append(proportion1 );
		       sb.append("%</td></tr>");
		    }
	    }
	     strFileName = strCity+strTown+"测试完成比例表.xls";//自定义xls文件的文件
	} 
	else if(exportFlag.equals("results_oneac"))
	{
	    //if(!strOneAc.equals("")){
       ///    tWhere += " and strclassonehp  LIKE '%"+ strOneAc +"%'";     
       // }
	    Vector<Proportion> vctObj=obj.list3(tWhere,intStartNum,intPageSize);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list3(tWhere,0,0);
		}
   	  
	    sb.append("<tr><td>城市</td><td>区县</td><td>一级热点</td><td>二级热点数量</td><td>AP数量</td><td>已测AP数</td><td>已测AP百分比</td></tr>");
	    if (vctObj.size() != 0)
	    {
	    double proportion1  = 0;
        int num = 0;
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		        num = vctObj.get(i).getTestAp(strCity,strTown, vctObj.get(i).getStrOneAc(),strStartTime,strEndTime);
            	if(vctObj.get(i).getAp(strCity,strTown,vctObj.get(i).getStrOneAc())!=0){
            	 proportion1 =  num*100/vctObj.get(i).getAp(strCity,strTown,vctObj.get(i).getStrOneAc());
            	 }else{
            	 proportion1 = 0;
            	 }
		       sb.append("<tr><td>"+strCity);
		       sb.append("</td><td>");
		       sb.append(strTown);
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getStrOneAc());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getTwoAcNum()) ;
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getAp(strCity,strTown,vctObj.get(i).getStrOneAc())) ;
		       sb.append("</td><td>");
		       sb.append(num );
		       sb.append("</td><td>");
		       sb.append(proportion1 );
		       sb.append("%</td></tr>");
		    }
	    }
	     strFileName = strCity+strTown+"一级热点"+strOneAc+"测试完成比例表.xls";//自定义xls文件的文件
	} 
	
	else if(exportFlag.equals("results_twoac"))
	{
	    //if(!strTwoAc.equals("")) tWhere += " and a.classtwoac ='" + strTwoAc + "' ";
	    Vector<Proportion> vctObj=obj.list4(tWhere,intStartNum,intPageSize);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list4(tWhere,0,0);
		}
   	  
	    sb.append("<tr><td>城市</td><td>区县</td><td>一级热点</td><td>二级热点</td><td>AP数量</td><td>已测AP数</td><td>已测AP百分比</td></tr>");
	    if (vctObj.size() != 0)
	    {
	    double proportion1  = 0;
        int num = 0;
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       num = vctObj.get(i).getTestAp(strCity,strTown,strOneAc, vctObj.get(i).getStrTwoAc(),strStartTime,strEndTime);
            	if(vctObj.get(i).getAp(strCity,strTown,strOneAc,vctObj.get(i).getStrTwoAc())!=0){
                 proportion1 =  num*100/vctObj.get(i).getAp(strCity,strTown,strOneAc,vctObj.get(i).getStrTwoAc());
            	 }else{
            	 proportion1 = 0;
            	 }
		       sb.append("<tr><td>"+strCity);
		       sb.append("</td><td>");
		       sb.append(strTown);
		       sb.append("</td><td>");
		       sb.append(strOneAc);
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getStrTwoAc()) ;
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getAp(strCity,strTown,strOneAc,vctObj.get(i).getStrTwoAc())) ;
		       sb.append("</td><td>");
		       sb.append(+num );
		       sb.append("</td><td>");
		       sb.append(proportion1 );
		       sb.append("%</td></tr>");
		    }
	    }
	     strFileName = strCity+strTown+"一级热点"+strOneAc+"的二级热点"+strTwoAc+"测试完成比例表.xls";//自定义xls文件的文件
	}
	
	else if(exportFlag.equals("results_ap"))
	{
	    Vector<Proportion> vctObj=obj.list5(WhereAp,intStartNum,intPageSize);
	   //获取当前页的记录条数
     	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list5(WhereAp,0,0);
		}
   	  
	    sb.append("<tr><td>城市</td><td>区县</td><td>一级热点</td><td>二级热点</td><td>AP名称</td><td>是否被测试</td></tr>");
	    if (vctObj.size() != 0)
	    {
		    for (int i = 0; i < vctObj.size(); i++)
		    {
		       sb.append("<tr><td>"+strCity);
		       sb.append("</td><td>");
		       sb.append(strTown);
		       sb.append("</td><td>");
		       sb.append(strOneAc);
		       sb.append("</td><td>");
		       sb.append(strTwoAc) ;
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).getStrApName());
		       sb.append("</td><td>");
		       sb.append(vctObj.get(i).isTest(vctObj.get(i).getStrMac(),strStartTime,strEndTime) );
		       sb.append("</td></tr>");
		    }
	    }
	     strFileName = strCity+strTown+"一级热点"+strOneAc+"的二级热点"+strTwoAc+"AP测试完成比例表.xls";//自定义xls文件的文件
	}
	System.out.println("================================"+strFileName);
	///strFileName="ffffffffffffffffff";
	sb.append("</table></body></html>");
	System.out.println(sb);
	if(!exportFlag.equals(null)){
			response.setContentType("APPLICATION/*");
	    response.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1" ));
	    out.clearBuffer(); 
	    out = pageContext.pushBody();
	    ServletOutputStream output = response.getOutputStream();
	    output.write(sb.toString().getBytes("utf-8"));
	}

	
%>
<%@ include file="../include/jsp/footer.jsp"%>
